from Globals import *

vetoPeople = ([])
callback = None
def run():
	'''
	Indien de mediacontroller is geblockt kan je met deze plugin toch nog een liedje stoppen. 
	'''
	global hook
	print "[Veto] Up and running!"
	hook.registerHook('setCallback_before', getCallback)
	hook.registerHook('handler_loop', addVeto)
	hook.registerHook('playSong_before', clearVeto)


def clearVeto(args):
	print "Veto has been cleared!"
	del vetoPeople[:]

def addVeto(args):
	if re.match("^veto(\r|\n){0,}$",args['data'],re.IGNORECASE) and args['client'].getpeername()[0] not in vetoPeople:
		vetoPeople.append(args['client'].getpeername()[0])
		if len(vetoPeople) > 3:
			callback.stopPlaying()

def getCallback(args):
	callback = args['callback']
